package com.leetcode.LC;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LC1200 {
    public List<List<Integer>> minimumAbsDifference(int[] arr) {

        ArrayList<List<Integer>> list = new ArrayList<>();
        Arrays.sort(arr);
        int min=Integer.MAX_VALUE;
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i+1]-arr[i]<min){
                list.clear();
                min=arr[i+1]-arr[i];
                list.add(Arrays.asList(arr[i],arr[i+1]));
            }else if (arr[i+1]-arr[i]==min){
                list.add(Arrays.asList(arr[i],arr[i+1]));
            }
        }
        
        return list;
    }

    public static void main(String[] args) {
        for (List<Integer> list : new LC1200().minimumAbsDifference(new int[]{3,8,-10,23,19,-4,-14,27})) {
            for (Integer integer : list) {
                System.out.print(integer+",");
            }
            System.out.println();
        }
    }
    
}
